package com.yl.ydk.ui.activity

import android.view.View
import cn.jzvd.Jzvd
import com.yl.ydk.R
import com.yl.ydk.base.BaseActivity
import com.yl.ydk.bean.VideoListBean
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_video_play.*


class VideoPlayActivity : BaseActivity(), View.OnClickListener {

    private var data: VideoListBean.Data.DataX? = null

    override fun getLayoutId(): Int = R.layout.activity_video_play


    override fun attachView() {

    }

    override fun detachView() {

    }

    override fun initView() {
        rlBack.setOnClickListener(this)
        jzvdStd.setOnClickListener(this)
        data = Gson().fromJson<VideoListBean.Data.DataX>(
            intent.getStringExtra("data"),
            VideoListBean.Data.DataX::class.java
        )
        data?.let {
            jzvdStd.setUp(it.video_url, "")
            jzvdStd.startVideo()
            tvTitle.text = it.title
        }
    }

    override fun onBackPressed() {
        if (Jzvd.backPress()) {
            return
        }
        super.onBackPressed()
    }

    override fun onPause() {
        super.onPause()
        Jzvd.releaseAllVideos()
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.rlBack -> {
                finish()
            }

            R.id.jzvdStd -> {
                if (flTitle.visibility == View.VISIBLE) {
                    flTitle.visibility = View.GONE
                } else {
                    flTitle.visibility = View.VISIBLE
                }
            }

        }
    }

}